package cn.lecosa.spark.mysql
import java.sql.DriverManager
import org.apache.spark.rdd.JdbcRDD
import org.apache.spark.{ SparkConf, SparkContext }
import org.apache.spark.sql.SQLContext
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import org.apache.spark.sql.SaveMode

object DuplicateTab {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("wow,My First Spark App!");
    conf.setMaster("local[2]");
    val sc = new SparkContext(conf);
    val sqlContext = new SQLContext(sc);
    import sqlContext.implicits._
    val jdbcdf = sqlContext.read.format("jdbc").options(Map("url" -> "jdbc:mysql://park01:3306/test", "driver" -> "com.mysql.jdbc.Driver", "dbtable" -> "test.emp", "user" -> "root", "password" -> "root")).load()
    jdbcdf.createTempView("ticket")
    //    val jdbcdf = sqlContext.load("jdbc", Map("url" -> "jdbc:oracle:thin:@10.20.8.94:1521:orcl?user=QZ&password=skycomm123", "dbtable" -> "TYID"))
    val df = sqlContext.sql("SELECT * from ticket");

//    val dataResult = df.write.mode(SaveMode.Append).jdbc("jdbc:mysql://park01:3306/test", "t_spark_dataframe_test", JdbcUtil.getProp()) // 表可以不存在

    df.show();
    df.schema;
  }

}